<template>
	<view class="page">
		<view class="header">
			<view class="header-title">
				<image src="/static/icon1.png" class="icon1"></image>
				<text class="title-text">借钱不求人 急用钱找我们!</text>
			</view>

			<view class="credit-card">
				<view class="credit-info">
					<text class="credit-label">您的预估授信额度(元)</text>
					<text class="credit-amount">{{crediAmount}}</text>
					<text class="credit-note">*具体审批额度以实际审核为准</text>
					<view class="progress-box">
						<view class="progress-bar">
							<view class="progress-inner" :style="{ width: progress + '%' }"></view>
						</view>
						<text class="progress-text">{{progress}}%</text>
					</view>
				</view>
				<image class="overlay-image" src="/static/info-top-rightIcon-DWbUzYze.png" mode="aspectFit" />
			</view>
		</view>

		<view class="content">

			<view class="property-section">
				<view class="section-header">
					<text class="section-title">完善 相关信息 提升审批通过率</text>
					<image src="/static/icon_title_right.png" class="right-arrow"></image>
				</view>

				<!--相关信息列表 -->
				<view style="padding-bottom: 10rpx;">

					<FoldContainer v-for="(data, index) in addedList" :title="data.title" :contents="data.listData"
						@check-event="handleChildEvent">
					</FoldContainer>

				</view>

			</view>

			<MoreInfo @more-info="handlMoreEvent"></MoreInfo>





			<view class="agreement">
				<checkbox @click="isSelected" />
				<view class="agreement-text">
					<text>我阅读并已同意</text>
					<!-- <text class="link">《个人信息共享授权书》</text> -->
					<text class="link" @click="linkProtocol(2)">《用户服务及隐私协议》</text>
				</view>
			</view>

			<button class="submit-btn" type="primary" @click="submitData">提交审核</button>

			<view class="footer">
				<text class="security-text">数据加密保护，仅用于申请审核</text>
				<view class="disclaimer">
					<p class="disclaimer-content">郑重声明：贷款有风险，借款需谨慎；</p>
					<p class="disclaimer-content">平台只提供贷款咨询和推荐服务，放款由银行或金融机构进行请根据个人能力合理贷款，理性消费，避免逾期；</p>
					<p class="disclaimer-content">贷款额度，放款时间以实际审批结果为准；</p>
					<p class="disclaimer-content">所有贷款申请在未成功贷款前绝不收取任何费用，为了保证您的资金安全，请不要相信任何要求您支付费用的信息、邮件、电话等不实信息。</p>
				</view>
			</view>
		</view>
		<FinishDialog @update-visible="onDialogClick" :visible="dgVisiable" :content="finishDialogContent"
			:buttonTitle="finishDialogBtnTitle"></FinishDialog>

	</view>
</template>

<script>
	// 页面逻辑部分
	import request from '@/js/request.js';
	export default {
		data() {
			return {
				respCode: 200,
				finishDialogContent: "您的提交已收到,稍后将有工作人员致电 请注意接听电话",
				finishDialogBtnTitle: "我知道了",
				currentUrl: "",
				//提交给服务器的数据
				postData: {
					//客户手机号码
					//客户名称
					customerName: "",
					//需求金额
					requiredAmount: "",
					//省份
					province: "",
					//市区
					city: "",
					//电话
					phone: "",
					/**
					 * 0:有房产 1:无房产
					 */

					house: 1,

					/**
					 * 0:有车产 1:无车产
					 */

					car: 1,

					/**
					 * 0:有公积金 1:无公积金
					 */
					providentFund: 1,

					/**
					 * 0:有社保 1:无社保
					 */
					socialSecurity: 1,

					/**
					 * 0:有营业执照 1:无营业执照
					 */
					businessLicense: 1,
					/**
					 * 商业保险 -1(未选择),0(无 )1(6个月以下 )，2(6-12个月 )， 3(12个月以上)，
					 */
					commericalInsurance: 0,


					// 贷款时间-1(未选择)2(6个月)3(12个月)4(24个月)5(36个月)

					loanTime: -1,
					/**
					 * 职业 1(上班族) 2(自由职业)3(私营企业主)4(国企/事业单位/公务员)
					 */
					profession: -1,


					/**
					 * 逾期记录 -1(未选择),1(信用良好),2(当前逾期中)
					 */

					overdue: -1,

					/**
					 * 0:700分以上 1:650-700分  2:600-650分  3:600分以下
					 */
					creditScore: 3,
					//数据类型 0:审核页数据  1:跳转页数据
					//todo：需要修改的
					dataType: 1,
					siteUrl: "",
					info: ""



				},
				phone: "",
				//客户贷款申请金额
				crediAmount: 6000000,
				//是否同意协议
				isAgree: false,
				//控制对话框显示
				dgVisiable: false,
				//进度条进度
				progress: 0,
				//完善相关信息组件返回的数据
				personalData: {},
				//checkbox 数据
				addedList: [{
					title: "名下房产",
					listData: [{
							name: "有房产",
							isGood: true
						},
						{
							name: "无房产",
							isGood: false
						},
					]

				}], // 用于存储图片路径的数组
				contentList: [{
						title: "名下车产",
						listData: [{
								name: "有车产",
								isGood: true
							},
							{
								name: "无车产",
								isGood: false
							},
						]

					},
					{
						title: "公积金",
						listData: [
							// {
							// 	name: "6个月以下",
							// 	isGood: false
							// },
							// {
							// 	name: "6-12个月",
							// 	isGood: false
							// },
							// {
							// 	name: "12个月以上",
							// 	isGood: false
							// },
							{
								name: "有公积金",
								isGood: true
							},
							{
								name: "无公积金",
								isGood: false
							}
						]


					},
					{
						title: "社保",
						listData: [
							// {
							// 	name: "6个月以下",
							// 	isGood: false
							// },
							// {
							// 	name: "6-12个月",
							// 	isGood: false
							// },
							// {
							// 	name: "12个月以上",
							// 	isGood: false
							// },
							{
								name: "有社保",
								isGood: true
							}, {
								name: "无社保",
								isGood: false
							}
						]


					},
					{
						title: "有营业执照",
						listData: [{
								name: "有营业执照",
								isGood: true
							},
							{
								name: "无营业执照",
								isGood: false
							}
						]


					},
					{
						title: "贷款时间",
						listData: [{
								name: "6个月",
								isGood: false
							},
							{
								name: "12个月",
								isGood: false
							},
							{
								name: "24个月",
								isGood: false
							},
							{
								name: "36个月",
								isGood: false
							}
						]


					},
					{
						title: "职业",
						listData: [{
								name: "上班族",
								isGood: false
							},
							{
								name: "自由职业",
								isGood: false
							},
							{
								name: "私营企业主",
								isGood: false
							},
							{
								name: "国企",
								isGood: false
							},
							{
								name: "事业单位",
								isGood: false
							},
							{
								name: "公务员",
								isGood: false
							}
						]


					},



					{
						title: "商业保险",
						listData: [{
								name: "6个月以下",
								isGood: false
							},
							{
								name: "6-12个月",
								isGood: false
							},
							{
								name: "12个月以上",
								isGood: false
							},
							{
								name: "无",
								isGood: false
							},

						]


					},


					{
						title: "逾期记录",
						listData: [{
								name: "信用良好",
								isGood: false
							},
							{
								name: "当前逾期中",
								isGood: false
							}
						]


					},

					{
						title: "芝麻分",
						listData: [{
								name: "700分以上",
								isGood: true
							},
							{
								name: "650-700分",
								isGood: true
							},
							{
								name: "600-650分",
								isGood: false
							},
							{
								name: "600分以下",
								isGood: false
							}
						]


					}





				]
			};
		},
		onLoad(options) {
			// 解析接收到的查询字符串参数
			console.log("options:", JSON.stringify(options));
			var receivedData = {
				userPhone: decodeURIComponent(options.userPhone),
				amount: parseInt(options.amount)
			};
			this.crediAmount = receivedData.amount;
			this.phone = receivedData.userPhone;
			if (!this.crediAmount) {
				this.crediAmount = 50000;
			}

			this.getCurrentUrl();



			// var keyword=getQueryString('kw')||'其他';

		},
		methods: {
			linkProtocol(index) {
				uni.navigateTo({
					url: "/pages/index/infoShare/infoShare"
				});
			},
			//协议勾选触发
			isSelected() {
				this.isAgree = !this.isAgree;
				console.log("isSelected", this.isAgree);

			},
			addEelement() {
				// 每次点击按钮，向addedList中添加一个图片路径
				// this.imageList.push(this.defaultImageSrc);
				if (this.contentList.length > 0) {
					const removedElement = this.contentList.shift();
					// console.log('removedElement：', removedElement);
					this.addedList.push(removedElement);
					this.progress = Math.trunc((this.addedList.length - 1) * 100 / 6);

				} else {
					this.progress = 100;

				}


			},
			getCurrentUrl() {

				this.currentUrl = window.location.href;
				console.log("currentUrl:", this.currentUrl);

			},
			//提交数据到服务器
			submitData() {
				// this.postData.house = 1;
				// this.postData.car = 1;
				// this.postData.providentFund = 1;
				// this.postData.socialSecurity = 1;
				// {"name":"","age":"","gender":0,"address":"内蒙古自治区-呼和浩特市"}
				if (this.postData.businessLicense == 1 &&
					this.postData.socialSecurity == 1 &&
					this.postData.car == 1 &&
					this.postData.house == 1 &&
					this.postData.providentFund == 1) {

					uni.showToast({
						title: '您不符合贷款资质，无法申请，房产、车产、公积金、社保、营业执照必须有一项满足条件！',
						icon: 'none'
					});
					return;
				}

				if (!this.personalData.name) {
					uni.showToast({
						title: '请输入你的姓名！',
						icon: 'none'
					});
					return;
				}
				this.postData.customerName = this.personalData.name;
				if (!this.personalData.age) {
					uni.showToast({
						title: '请输入你的年龄！',
						icon: 'none'
					});
					return;
				}
				var t = {
					年龄: this.personalData.age,
					性别: this.personalData.gender == 1 ? "男" : "女"
				}
				this.postData.info = JSON.stringify(t);
				if (!this.personalData.address) {
					uni.showToast({
						title: '请选择地址！',
						icon: 'none'
					});
					return;
				}
				//取地址
				const parts = this.personalData.address.split("-", 2);
				if (parts.length > 0) {
					this.postData.province = parts[0];
				}
				// 如果分割后的数组长度大于 1，则将第二部分赋值给 part2
				if (parts.length > 1) {
					this.postData.city = parts[1]
				}
				if (!this.isAgree) {
					uni.showToast({
						title: '请勾选我已阅读同意共享信息授权书！',
						icon: 'none'
					});
					return;
				}
				this.postData.requiredAmount = this.crediAmount + "";
				this.postData.phone = this.phone;
				this.postData.siteUrl = this.currentUrl;
				console.log("提交数据：", JSON.stringify(this.postData));
				this.submitHttp();


			},
			//提交数据到服务器
			async submitHttp() {
				try {
					var resp = await request("/api/credit/webSaveData", this.postData);
					this.dgVisiable = true;
					this.respCode = resp.code;
					//todo悟空代码

					cli_copy("");

					// if (resp.code === 201) {
					// 	this.finishDialogBtnTitle = "领取额度";
					// } else {
					// 	this.finishDialogBtnTitle = "我知道了";
					// }
					// this.finishDialogContent = resp.msg;
				} catch (error) {
					//TODO handle the exception
				}
			},
			//点击chekbox传过来的数据
			handleChildEvent(data) {


				console.log("receivedData:", data);
				if (data.content == "有房产") {
					this.postData.house = 0;
				}
				if (data.content == "无房产") {
					this.postData.house = 1;
				}
				if (data.content == "有车产") {
					this.postData.car = 0;
				}
				if (data.content == "无车产") {
					this.postData.car = 1;
				}
				if (data.parent == "公积金") {
					// if (data.content == "6个月以下") {
					// 	this.postData.providentFund = 2;
					// }
					// if (data.content == "6-12个月") {
					// 	this.postData.providentFund = 3;
					// }
					// if (data.content == "12个月以上") {
					// 	this.postData.providentFund = 4;
					// }
					if (data.content == "无公积金") {
						this.postData.providentFund = 1;
					} else {
						this.postData.providentFund = 0;
					}
				}
				if (data.parent == "社保") {
					// if (data.content == "6个月以下") {
					// 	this.postData.socialSecurity = 2;
					// }
					// if (data.content == "6-12个月") {
					// 	this.postData.socialSecurity = 3;
					// }
					// if (data.content == "12个月以上") {
					// 	this.postData.socialSecurity = 4;
					// }
					if (data.content == "无社保") {
						this.postData.socialSecurity = 1;
					} else {
						this.postData.socialSecurity = 0;
					}
				}

				if (data.parent == "商业保险") {
					if (data.content == "6个月以下") {
						this.postData.commericalInsurance = 1;
					}
					if (data.content == "6-12个月") {
						this.postData.commericalInsurance = 2;
					}
					if (data.content == "12个月以上") {
						this.postData.commericalInsurance = 3;
					}
					if (data.content == "无") {
						this.postData.commericalInsurance = 0;
					}
				}

				//贷款时间-1(未选择)2(6个月)3(12个月)4(24个月)5(36个月)
				if (data.parent == "贷款时间") {
					if (data.content == "6个月") {
						this.postData.loanTime = 2;
					}
					if (data.content == "12个月") {
						this.postData.loanTime = 3;
					}
					if (data.content == "24个月以上") {
						this.postData.loanTime = 4;
					}
					if (data.content == "36个月") {
						this.postData.loanTime = 5;
					}
				}
				//逾期记录 -1(未选择),1(信用良好),2(当前逾期中)
				if (data.parent == "逾期记录") {
					if (data.content == "信用良好") {
						this.postData.overdue = 1;
					}
					if (data.content == "当前逾期中") {
						this.postData.overdue = 2;
					}

				}
				//职业 1(上班族) 2(自由职业)3(私营企业主)4(国企/事业单位/公务员)
				if (data.parent == "职业") {
					if (data.content == "上班族") {
						this.postData.profession = 1;
					}
					if (data.content == "自由职业") {
						this.postData.profession = 2;
					}
					if (data.content == "私营企业主") {
						this.postData.profession = 3;
					}
					if (data.content == "国企" ||
						data.content == "事业单位" ||
						data.content == "公务员") {
						this.postData.profession = 4;
					}

				}


				if (data.content == "有营业执照") {
					this.postData.businessLicense = 0;
				}
				if (data.content == "无营业执照") {
					this.postData.businessLicense = 1;
				}
				if (data.content == "700分以上") {
					this.postData.creditScore = 0;
				}
				if (data.content == "650-700分以上") {
					this.postData.creditScore = 1;
				}
				if (data.content == "600-650分") {
					this.postData.creditScore = 2;
				}
				if (data.content == "600分以下") {
					this.postData.creditScore = 3;
				}
				//





				var len = this.addedList.length;
				// var index = this.addedList.indexOf(data.title)


				this.addEelement();


			},
			handlMoreEvent(data) { //客户真是姓名年龄、性别、地区数据
				this.personalData = data;
				console.log("more info:", JSON.stringify(this.personalData));
			},
			onDialogClick(data) { //对话框点击事件
				this.dgVisiable = data;
				console.log("onDialogClick:", data);
				//跳转到首页
				// 跳转地址：
				// bddc01.tztcstock888.cn对应：https://pkgz.tulcn.cn/cwLLOf
				// ksdc01.tianmingloan.com  对应：https://pkgz.tulcn.cn/cVFOrU
				if (this.respCode == 201) {
					//https://pkgz.tulcn.cn/cVFOrU

					//todo:需要修改的 跳转到指定页面
					//左新凰
					// const url = 'https://pkgz.tulcn.cn/cwLLOf';
					//天明
					// const url = 'https://pkgz.tulcn.cn/cVFOrU';
					//微克
					// const url = "https://pkgz.tulcn.cn/cVFOrU";
					//其他
					// const url="https://pkgz.tulcn.cn/cJRfHZ";
					//跳转地址三
					// const url = "https://pkgz.tulcn.cn/cckqEs";

					// window.open(url, '_blank');
					uni.redirectTo({
						url: "/pages/index/index"
					});

				} else {
					uni.redirectTo({
						url: "/pages/index/index"
					});
				}

			}
		}
	};
</script>

<style scoped>
	.page {
		padding: 30rpx;
		min-height: 100%;
		background: linear-gradient(to bottom, #0D82E5 0%, #B9CEE6 50%, #F0F0F0 100%);
	}

	.header {
		padding: 40rpx 30rpx;
	}

	.header-title {
		color: #FFFFFF;
		display: flex;
		align-items: center;
		margin-bottom: 30rpx;
	}

	.title-text {
		color: #ffffff;
		font-size: 16px;
		margin-left: 10rpx;
	}

	.credit-card {
		position: relative;
		background: #ffffff;
		border-radius: 16rpx;
		padding: 30rpx;
		/* display: flex;
		justify-content: space-between;
		align-items: center; */
	}

	.credit-info {}

	.credit-label {
		font-size: 25rpx;
		color: #333;
		display: block;
	}

	.credit-amount {
		font-size: 90rpx;
		color: #0E82E5;
		font-weight: bold;
		margin: 20rpx 0;
		display: block;
	}

	.credit-note {
		font-size: 25rpx;
		color: #333;
		display: block;
		margin-bottom: 20rpx;
	}

	.progress-box {
		display: flex;
		align-items: center;
	}

	.progress-bar {
		flex: 1;
		height: 10rpx;
		background: #e5e5e5;
		border-radius: 5rpx;
		margin-right: 20rpx;
	}

	.progress-inner {
		height: 100%;
		background: #0080ff;
		border-radius: 5rpx;
	}

	.progress-text {
		font-size: 14px;
		color: #0080ff;
	}

	.coin-image {
		margin-top: -200rpx;
		width: 215rpx;
		height: 215rpx;
	}

	.content {
		/* background-color: #fff; */
		/* padding: 30rpx; */
	}

	.section-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx;
		background: #0E82E5;
		border-top-right-radius: 16rpx;
		border-top-left-radius: 16rpx;
		margin-bottom: 20rpx;
	}

	.section-title {
		font-size: 27rpx;
		color: #fff;
		font-weight: 500;
	}

	.property-section {
		background: #ffffff;
		border-radius: 16rpx;
		margin-bottom: 20rpx;
	}

	.property-title {
		font-size: 16px;
		color: #333333;
		font-weight: 500;
		margin-bottom: 10rpx;
		display: block;
	}

	.property-subtitle {
		font-size: 14px;
		color: #999999;
		margin-bottom: 30rpx;
		display: block;
	}

	.property-options {
		display: flex;
		gap: 20rpx;
	}

	.property-option {
		flex: 1;
		padding: 30rpx;
		border: 1px solid #e5e5e5;
		border-radius: 16rpx;
		display: flex;
		align-items: center;
		gap: 10rpx;
	}

	.tag {
		background: #fff2e5;
		color: #ff9500;
		font-size: 12px;
		padding: 4rpx 12rpx;
		border-radius: 8rpx;
		margin-left: auto;
	}

	.agreement {
		margin-top: 30rpx;
		display: flex;
		/* 允许子元素换行 */
		flex-wrap: wrap;
		/* 主轴方向的对齐方式，这里将子元素在水平方向居中 */
		justify-content: center;
		/* 多行元素在交叉轴方向的对齐方式，这里将多行元素在垂直方向居中 */
		align-content: center;


	}

	.agreement-text {
		display: flex;
		/* 主轴方向的对齐方式，将子元素在水平方向居中 */
		justify-content: center;
		/* 交叉轴方向的对齐方式，将子元素在垂直方向居中 */
		align-items: center;
		text-align: center;
		font-size: 22rpx;
		color: #000;
	}

	.link {
		color: #0080ff;
	}

	.submit-btn {
		width: 100%;
		height: 88rpx;
		line-height: 88rpx;
		background: linear-gradient(to right, #0E82E5 0%, #7FB5F1 100%);
		border-radius: 18rpx;
		color: #ffffff;
		font-size: 16px;
		margin: 40rpx 0;
	}

	.footer {
		text-align: center;
	}

	.security-text {
		font-size: 22rpx;
		color: #000;
		margin-bottom: 30rpx;
		display: block;
	}

	.disclaimer {
		text-align: center;
	}

	.disclaimer-title {
		font-size: 23rpx;
		color: #444444;
		font-weight: 500;
		display: block;
		margin-bottom: 10rpx;
	}

	.disclaimer-content {
		text-align: center;
		font-size: 23.61rpx;
		color: #444444;
		line-height: 1.6;
	}

	.icon1 {
		margin-top: 0.5%;
		width: 33rpx;
		height: 33rpx;

	}

	.right-arrow {
		width: 25.69rpx;
		height: 25.69rpx
	}

	.overlay-image {
		position: absolute;
		/* 相对于容器定位 */
		top: -60rpx;
		/* 向上移动图片高度的一半 */
		right: -8rpx;
		/* 向右移动图片宽度的一半 */
		width: 212.5rpx;
		height: 212.5rpx;
		z-index: 1;
		/* 确保图片在上面 */
	}
</style>